#ifndef __DEBUG__BERT
#define __DEBUG__BERT

#include <cstdio>
#include <cstring>
#include <cstdarg>
#include <cstdlib>
/**
 * The debug function just print info on screen
 * Some cmds are defined here, for test
 */
inline void debug(const char * fmt, ...)
{
	char buf[128] = {0};
	va_list ap;
	va_start(ap, fmt);
	int nBytes = vsnprintf(buf, sizeof(buf), fmt, ap);
	if ( nBytes > 0 )
		printf("\033[7;%d;40m%s\033[0m\n", rand()%7+31, buf);
}

const unsigned char NULL_CMD   = 0; // 0 is for heartbeat
const unsigned char NULL_PARAM = 0; // 0 is error
struct NullBaseCmd // The cmd base struct
{
	NullBaseCmd() : byCmd(NULL_CMD), byParam(NULL_PARAM)
	{
	}
	unsigned char byCmd;
	unsigned char byParam;
};

const unsigned char SERVER_TEST_PARAM = 1;
struct ServerTestCmd : public NullBaseCmd
{
	ServerTestCmd()
	{
		byParam = SERVER_TEST_PARAM ;
	}
};

const unsigned char CLIENT_TEST_PARAM = 2;
struct ClientTestCmd : public NullBaseCmd
{
	ClientTestCmd()
	{
		byParam = CLIENT_TEST_PARAM ;
	}
};
//for example
const unsigned char LOGIN_CMD = 1;// override byCmd
struct LoginCmd : public NullBaseCmd
{
	LoginCmd()
	{
		byCmd = LOGIN_CMD;
	}
};

const unsigned char REQUEST_LOGIN_PARAM_SS = 1;// override byparam
struct RequestLoginCmd : public LoginCmd
{
	RequestLoginCmd()
	{
		byParam = REQUEST_LOGIN_PARAM_SS;
	}
};

const unsigned char RETURN_LOGIN_PARAM_SS = 2;// override byparam
struct ReturnLoginCmd: public LoginCmd
{
	ReturnLoginCmd()
	{
		byParam = RETURN_LOGIN_PARAM_SS ;
		state = 0;//fail
	}
	unsigned char state;
};

const unsigned char SENDINFO_LOGIN_PARAM_CS = 3;// client to gw
struct SendInfoLoginCmd : public LoginCmd
{
	SendInfoLoginCmd()
	{
		byParam = SENDINFO_LOGIN_PARAM_CS ;
	}
	unsigned char name[8];
	unsigned char pwd[8];
};

#endif

